//
//  MarketCollectionViewCell.m
//  cityCar
//
//  Created by 常宽 on 14/10/31.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MarketCollectionViewCell.h"
#import "MarketPullView.h"
#import "PullView.h"
#import "WebColor.h"
#import "CityName.h"

@interface MarketCollectionViewCell ()

@end

@implementation MarketCollectionViewCell

- (void)dealloc
{
    [_city release];
    [_province release];
    [_pullView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.pullView = [[MarketPullView alloc]init];
        self.city = [NSString string];
        self.province = [NSString string];
        [self.contentView addSubview:_pullView];
        [_pullView release];
        
        NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
        [notiCenter addObserver:self selector:@selector(notiCenterAction:) name:@"CityName" object:nil];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self setupSubViews];
}

- (void)setupSubViews
{
    CGFloat w = self.contentView.frame.size.width;
    CGFloat h = self.contentView.frame.size.height;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 5, w, 30)];
    view.backgroundColor = [WebColor lightCyan];
    [self.contentView addSubview:view];
    [view release];
    
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, w / 5, view.frame.size.height)];
    title.textColor = [UIColor lightGrayColor];
    title.font = [UIFont boldSystemFontOfSize:15.f];
    title.text = @"行情文章";
    [view addSubview:title];
    [title release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(w - (w / 5 * 2), 0, (w / 5 * 2), view.frame.size.height);
    [button setTitle:self.pullView.city forState:UIControlStateNormal];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(pushNewView:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];

    _pullView.Frame = CGRectMake(5, view.frame.size.height + view.frame.origin.y, w - 10, h - (view.frame.size.height + view.frame.origin.y));
    

    
}
- (void)pushNewView:(UIButton *)button
{
    self.block(button.titleLabel.text);
}
// 收通知
- (void)notiCenterAction:(NSNotification *)noti
{
    // 收到通知之后要执行的方法
    NSLog(@"地址接收通知");
    NSLog(@"%@ == %@", noti.object, noti.userInfo);
    CityName *city = noti.object;
    self.pullView.province = city.pro;
    self.pullView.city = city.city;

    self.pullView.countx = 1;
    [self.pullView.bigArray removeAllObjects];

    [self.pullView layoutSubviews];
    [self layoutSubviews];
    
    
}

@end
